package com.shuang.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shuang.common.PageObject;
import com.shuang.mapper.DbReceiveInformationMapper;
import com.shuang.pojo.DbReceiveInformation;
import com.shuang.pojo.DbReceiveInformationExample;
import com.shuang.pojo.DbReceiveInformationExample.Criteria;
import com.shuang.service.DbReceiveInformationService;
@Service("dbReceiveInformationService")
public class DbReceiveInformationServiceImpl implements DbReceiveInformationService {
	
	@Resource(name="dbReceiveInformationMapper")
	private DbReceiveInformationMapper  dbReceiveInformationMapper;
	
	@Override
	public PageObject<DbReceiveInformation> getReceiveInfoList(int page,int rows) {
		DbReceiveInformationExample example = new DbReceiveInformationExample();
		//分页处理
		PageHelper.startPage(page, rows);
		//分页查询
		List<DbReceiveInformation> list = dbReceiveInformationMapper.selectByExample(example);
		//获取分页信息对象
		PageInfo<DbReceiveInformation> pageInfo=new PageInfo<DbReceiveInformation>(list);
				
		PageObject<DbReceiveInformation> pageObject=new PageObject<DbReceiveInformation>(pageInfo.getTotal(),list);
		//实例化分页对象
		return pageObject;
	}

	@Override
	public Map<String,Object> saveInformation(DbReceiveInformation record) {
		Map<String,Object> map=new HashMap<String, Object>();
		record.setRiUpdateTime(new Date());
		record.setRiCreateTime(new Date());
		int result = dbReceiveInformationMapper.insert(record);
		if(result>0){
			map.put("status", 200);
		}else{
			map.put("status", 403);
		}
		return map;
	}

	@Override
	public List<DbReceiveInformation> getReceiveInfomationByUid(Long getuId) {
		DbReceiveInformationExample example = new DbReceiveInformationExample();
		Criteria criteria = example.createCriteria();
		criteria.andUIdEqualTo(getuId);
		example.setOrderByClause("ri_update_time desc");
		List<DbReceiveInformation> result = dbReceiveInformationMapper.selectByExample(example);
		return result;
	}

	@Override
	public DbReceiveInformation getReceiveInfomationByRiId(Long riId) {
		return dbReceiveInformationMapper.selectByPrimaryKey(riId);
		 
	}
}
